// JavaScript Document

function isKeyTrigger(e,keyCode){
    var argv = isKeyTrigger.arguments;
    var argc = isKeyTrigger.arguments.length;
    var bCtrl = false;
    if(argc > 2){
        bCtrl = argv[2];
    }
    var bAlt = false;
    if(argc > 3){
        bAlt = argv[3];
    }

    var nav4 = window.Event ? true : false;

    if(typeof e == 'undefined') {
        e = event;
    }

    if( bCtrl &&
        !((typeof e.ctrlKey != 'undefined') ?
            e.ctrlKey : e.modifiers & Event.CONTROL_MASK > 0)){
        return false;
    }
    if( bAlt &&
        !((typeof e.altKey != 'undefined') ?
            e.altKey : e.modifiers & Event.ALT_MASK > 0)){
        return false;
    }
    var whichCode = 0;
    if (nav4) whichCode = e.which;
    else if (e.type == "keypress" || e.type == "keydown")
        whichCode = e.keyCode;
    else whichCode = e.button;

    return (whichCode == keyCode);
}
function enter(e){
    var ie =navigator.appName=="Microsoft Internet Explorer"?true:false;
    if(ie){
        if(window.event.keyCode==13){doSomething();}
    }else{
        if(isKeyTrigger(e,13)){doSomething();}
    }
}

function doSomething(){
	$("#login").click();
}
$(function(){
	$("#login").click(function(){
		alert(0);
		if(!$("#logName").val() || !$("#password").val()){
			$("#tip").html("请输入用户名或密码！");
			$("#tip").show();
		}else{
			$("#tip").hide();
			var postUrl = "./action/adminLogin&logName=" + $("#logName").val() + "&password=" +  $("#password").val() + "&stamp=" + new Date().getTime();
			alert(1);
			$.post(postUrl,
				   "",
				   function(html){
				   		alert(2);
					   if(html && html.indexOf("ok")>=0){
						   if(url && url!="null"){
							   window.location = url;
						   }else{
							   window.location = "./publish";
						   }
					   }else{
							$("#tip").html("用户名或密码错误！");
							$("#tip").show();
					   }
					});
		}
	});
});